import okhttp3.*;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class OkHttpUtil {
    private static OkHttpClient okHttpclient = null;

    static {
        okHttpclient = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS)
                .build();
    }

    public static String run(String url,String json) throws Exception {
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        String jsonStr = json;
        RequestBody body = RequestBody.create(JSON, jsonStr);


        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();
        Response response = okHttpclient.newCall(request).execute();
//        System.out.println(response.body().string());
        //System.out.println(response);
        if (!response.isSuccessful()) {
            throw new IOException("Unexpected code " + response);
        }
        return response.body().string();

    }


}
//测试冲突
//bbbb
//ccc


